package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/** 块读写的文件复制 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis1=new FileInputStream("K.jpg");
        FileOutputStream fos1=new FileOutputStream("K_cp1.jpg");
        long start1=System.currentTimeMillis();
        byte[] data1=new byte[1024*10];
        int len1;
        while ((len1=fis1.read(data1))!=-1){
            fos1.write(data1);
        }
        long end1=System.currentTimeMillis();
        System.out.println("复制完毕！耗时:"+(end1-start1)+"ms");
        fis1.close();
        fos1.close();


        FileInputStream fis2=new FileInputStream("K.jpg");
        FileOutputStream fos2=new FileOutputStream("K_cp2.jpg");
        long start2=System.currentTimeMillis();
        byte[] data2=new byte[1024*10];
        int len2;
        while ((len2=fis2.read(data2))!=-1){
            fos2.write(data2);
        }
        long end2=System.currentTimeMillis();
        System.out.println("复制完毕!耗时:"+(end2-start2)+"ms");
        fis2.close();
        fos2.close();
    }
}
